define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'system_data/index' + location.search,
                    add_url: 'system_data/add',
                    edit_url: 'system_data/edit',
                    del_url: 'system_data/del',
                    multi_url: 'system_data/multi',
                    import_url: 'system_data/import',
                    table: 'system_data',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cargo_value', title: __('Cargo_value'), operate:'BETWEEN'},
                        {field: 'points', title: __('Points'), operate:'BETWEEN'},
                        {field: 'activity_points', title: __('Activity_points'), operate:'BETWEEN'},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            ,buttons:[
                                {
                                    name: 'edit_points',
                                    text: '修改平台积分',
                                    title: '修改平台积分',
                                    icon: 'fa fa-user',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    refresh: true,
                                    //判断按钮是否隐藏
                                    // hidden: function(row){
                                    //     return row.type == 1 ? true : false
                                    // },
                                    url: 'system_data/edit_points'
                                },
                                {
                                    name: 'edit_activity_points',
                                    text: '修改平台活动积分',
                                    title: '修改平台活动积分',
                                    icon: 'fa fa-user',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    refresh: true,
                                    //判断按钮是否隐藏
                                    // hidden: function(row){
                                    //     return row.type == 1 ? true : false
                                    // },
                                    url: 'system_data/edit_activity_points'
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        edit_points: function () {
            Controller.api.bindevent();
        },
        edit_activity_points: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
